package service

import (
	"census/context"
	"census/model"
	"errors"
)

type CommonService int

var (
	errServiceSignalStop = errors.New("service stop signal")
)

func (c *CommonService) SID() string {
	return "commonService"
}

func (c *CommonService) Run() (err error) {
	return nil
}

func (c *CommonService) Reload() (err error) {
	return nil
}

func (c *CommonService) Shutdown() (err error) {
	return nil
}

//写入口
//可扩展成分布式
//写入etcd等
func (c *CommonService) Send(rq *context.AppRequest) (err error) {
	select {
	case <-GetServiceChan():
		return errServiceSignalStop
	default:
	}
	p, err := model.GetProcessor(rq.AppName)
	if err != nil {
		return
	}
	err = p.Write(rq)
	return
}
